package com.js.purs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurCondition;
import com.js.purs.service.IPurConditionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 抽取条件Controller
 * 
 * @author lzq
 * @date 20240704
 */
@RestController
@RequestMapping("/condition")
public class PurConditionController extends BaseController
{
    @Autowired
    private IPurConditionService purConditionService;

    /**
     * 查询抽取条件列表
     */
    @RequiresPermissions("purs:condition:list")
    @GetMapping("/list")
    public TableDataInfo list(PurCondition purCondition)
    {
        startPage();
        List<PurCondition> list = purConditionService.selectPurConditionList(purCondition);
        return getDataTable(list);
    }

    /**
     * 导出抽取条件列表
     */
    @RequiresPermissions("purs:condition:export")
    @Log(title = "抽取条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurCondition purCondition)
    {
        List<PurCondition> list = purConditionService.selectPurConditionList(purCondition);
        ExcelUtil<PurCondition> util = new ExcelUtil<PurCondition>(PurCondition.class);
        util.exportExcel(response, list, "抽取条件数据");
    }

    /**
     * 获取抽取条件详细信息
     */
    @RequiresPermissions("purs:condition:query")
    @GetMapping(value = "/{conditionId}")
    public AjaxResult getInfo(@PathVariable("conditionId") Long conditionId)
    {
        return success(purConditionService.selectPurConditionByConditionId(conditionId));
    }

    /**
     * 新增抽取条件
     */
    @RequiresPermissions("purs:condition:add")
    @Log(title = "抽取条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<PurCondition> purCondition)
    {
        return toAjax(purConditionService.insertPurCondition(purCondition));
    }

    /**
     * 修改抽取条件
     */
    @RequiresPermissions("purs:condition:edit")
    @Log(title = "抽取条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurCondition purCondition)
    {
        return toAjax(purConditionService.updatePurCondition(purCondition));
    }

    /**
     * 删除抽取条件
     */
    @RequiresPermissions("purs:condition:remove")
    @Log(title = "抽取条件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{conditionIds}")
    public AjaxResult remove(@PathVariable String[] conditionIds)
    {
        return toAjax(purConditionService.deletePurConditionByConditionIds(conditionIds));
    }
}
